import pymysql


class DB:
    # 初始化
    def __init__(self):
        self.conn = pymysql.connect(host='localhost', port=3306, user='root', password='123', db='deng',
                                    charset='utf8', cursorclass=pymysql.cursors.DictCursor)
        self.coursor = self.conn.cursor()

    # 查找所有
    def findall(self, sql):
        self.coursor.execute(sql)
        return self.coursor.fetchall()

    # 查找单个
    def findone(self, sql):
        self.coursor.execute(sql)
        return self.coursor.fetchone()

    # 添加
    def insert(self, sql):
        self.coursor.execute(sql)
        self.conn.commit()

    # 关闭
    def close(self):
        self.coursor.close()
        self.conn.close()


db = DB()